package com.yuyou.tas.terminal.comm;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yuyou.tas.util.bean.ResBoolSimpleInfo;
import com.yuyou.tas.util.tool.HttpClient;

/**
 * 学生端接口
 * @author ZY
 *
 */
@Service
public class MUAPI {
		
	@Value("${yyfnAddr}")
	private String yyfnAddr;
		
	/**
	 * 手机登陆
	 */
	public  static String login="/api/m/login";
	
	/**
	 * 得到用户绑定的学员
	 */
	public  static String findCustomerBindStudent="/api/m/u/findCustomerBindStudent";

	/**
	 * 得到用户绑定的学员
	 * @param accessToken
	 * @return
	 * @throws Exception
	 */
	public CustomerBindStudentVo findCustomerBindStudent(String accessToken) throws Exception{
		Map<String, String> params=new HashMap<String, String>();
		params.put("accessToken", accessToken);	
		String res =HttpClient.post(yyfnAddr+findCustomerBindStudent, params,null);		
		CustomerBindStudentVo customerBindStudentVo=JSONObject.parseObject(res, new TypeReference<CustomerBindStudentVo>() {});	       		
		return customerBindStudentVo;
	}
	
	/**
	 * 检验此学生ID有效性
	 * @param accessToken
	 * @param studengId
	 * @return
	 * @throws Exception
	 */
	public ResBoolSimpleInfo<String> validaStu(String accessToken,Long studentId) throws Exception{
		ResBoolSimpleInfo<String> res=new ResBoolSimpleInfo<>();
		
		//去掉校验
		res.setSuccess(true);		
		return res;
		
//		//TODO remove
//		if(accessToken.equals("feedback_pc")){
//			res.setSuccess(true);		
//			return res;
//		}
//		
//		CustomerBindStudentVo customerBindStudentVo=this.findCustomerBindStudent(accessToken);
//		if(!customerBindStudentVo.isSuccess()){
//			res.setSuccess(false);
//			res.setMessage(customerBindStudentVo.getDesc());
//			return res;
//		}
//		long count=customerBindStudentVo.getData().stream().filter(item ->item.getStudentId().longValue()==studentId.longValue()).count();				
//		if(count>0){
//			res.setSuccess(true);		
//			return res;
//		}else{
//			res.setSuccess(false);
//			res.setMessage("暂无课堂反馈");
//			return res;
//		}

	}
	
	
	
	
	
}
